<template>
  <div class="lin-container" v-if="!showDetail">
    <!-- 列表页面 -->
    <div class="container"  >
      <div class="header"><div class="title">选择关联采购单</div></div>
      <!-- 表格 -->
      <lin-table
        :tableColumn="tableColumn"
        :tableData="tableData"
        :operate="operate"
        @handlePass="pass"
        @handleReject="reject"
        @handleProcess="handleProcess"
        @row-click="rowClick"
        v-loading="loading"
      ></lin-table>
    </div>

  </div>
  <div v-else>
    <return-detail @back="back"  :apply-list="applyList" ></return-detail>
  </div>
</template>

<script>

import LinTable from '@/component/base/table/lin-table'
import shopStock from '@/model/shopStock'
import shopList from '@/model/shopList'
import warehouseInput from '@/model/warehouseInput'
import returnDetail from './return-detail'

export default {
  name: 'return-audit',
  components: {
    returnDetail,
    LinTable,
  },
  data() {
    return {
      tableColumn: [{ prop: 'warehouse_input_id', label: '入库' }, { prop: 'create_time', label: '提交时间' }, { prop: 'username', label: '采购员' }, { prop: 'supplier', label: '供应商' }, { prop: 'status', label: '状态' }],
      tableData: [],
      operate: [],
      showEdit: false,
      showDetail: false,
      editBookID: 1,
      processListID: 1,
      applyList: [],
      loading: false
    }
  },
  async mounted() {
    this.loading = true
    // await this.getStocks()
    await this.getList()
    this.operate = [
      // { name: '通过', func: 'handlePass', type: 'success' },
      // {
      //   name: '驳回',
      //   func: 'handleReject',
      //   type: 'danger',
      // },
      {
        name: '查看',
        func: 'handleProcess',
        type: 'primary',
      },
    ]
    this.loading = false
    console.log(this.tableData)
  },

  methods: {
    async getStocks() {
      try {
        const shopStocks = await shopStock.getShopStocks()
        this.tableData = shopStocks
        console.log(shopStocks)
      } catch (error) {
        if (error.code === 10020) {
          this.tableData = []
        }
      }
    },
    async getList() {
      try {
        const list = await warehouseInput.getInputList()
        this.tableData = list
        console.log(list)
      } catch (error) {
        if (error.code === 10020) {
          this.tableData = []
        }
      }
    },
    reject(val) {
      console.log(val)
    },
    pass(val) {
      console.log(val)
      this.$confirm('确定要通过此申请吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'info',
      }).then(async () => {
        const res = await shopList.passReplenishApply(val.row.replenish_id)
        if (res.code < window.MAX_SUCCESS_CODE) {
          this.$message({
            type: 'success',
            message: res.message,
          })
        }
      })
    },
    handleProcess(val) {
      this.showDetail = true
      this.processListID = val.row.output_id
      this.applyList = val.row
      console.log(this.applyList)
    },

    async back() {
      this.showDetail = false
      this.loading = true
      // await this.getStocks()
      await this.getList()
      this.operate = [
        // { name: '通过', func: 'handlePass', type: 'success' },
        // {
        //   name: '驳回',
        //   func: 'handleReject',
        //   type: 'danger',
        // },
        {
          name: '查看',
          func: 'handleProcess',
          type: 'primary',
        },
      ]
      this.loading = false
      console.log(this.tableData)
    },
    handleEdit(val) {
      console.log('val', val)
      // this.showEdit = true
      // this.editBookID = val.row.id
    },
    handleDelete(val) {
      console.log('val', val)
    },
    rowClick() {
      console.log('rowclick')
    },
    editClose() {
      // this.showEdit = false
      // this.getBooks()
    },
  },
}
</script>

<style lang="scss" scoped>
.container {
  padding: 0 30px;

  .header {
    display: flex;
    justify-content: space-between;
    align-items: center;

    .title {
      height: 59px;
      line-height: 59px;
      color: $parent-title-color;
      font-size: 16px;
      font-weight: 500;
    }
  }

  .pagination {
    display: flex;
    justify-content: flex-end;
    margin: 20px;
  }
}
</style>
